package com.bw.coupon.controller;/**
 * @Author：尚志豪
 * @Package：com.bw.coupon.controller
 * @Project：doudi-group-practical_training-02
 * @name：OrderController
 * @Date：2025/1/23 16:42
 */

import com.alibaba.fastjson.JSON;
import com.bw.common.core.domain.Result;
import com.bw.coupon.domain.Order;
import com.bw.coupon.service.OrderService;
import org.json.JSONObject;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: doudi-group-practical_training-02
 * @description: 异步下单
 * @author: CuiFu Bo
 * @create: 2025-01-23 16:42
 **/
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;




    //下单服务
    @PostMapping("/placeOrder")
    public Result placeOrder(@RequestBody Order order){

        orderService.PlaceOrder(order);

        return Result.success(order.getOrderNumber(),"订单中，请稍后");
    }


    // 前台轮询查询订单状态
    @GetMapping("/order/status/{orderNumber}")
    public Result checkOrderStatus(@PathVariable Long orderNumber) {

        Integer state = orderService.checkOrderStatus(orderNumber);

        return Result.success(state);
    }


}
